//引入用来发送的请求方法
import {
  request
} from "../../request/index.js"
Page({
  data: {
    userinfo: {},
    // 导航 数组
    catesList: [],
    user: {},
  },
  exit: function () {
    wx.removeStorageSync('user');
    if (wx.getStorageSync('user') == "") {
      wx.showToast({
        title: "退出成功！",
        icon: 'none',
        duration: 1000,
        mask: true
      })
      this.onLoad();
    }
  },
  bin() {
    wx.showToast({
      title: '成功',
      image: "/icons/super.gif"
    })
  },
  onLoad: function (options) {
    this.showUserInfo();
    // console.log(this.data.user);
  }, 
  onTabItemTap(){
    this.showUserInfo();
    // console.log(this.data.user);
  },
  //加载显示用户信息
  showUserInfo() {
    //未登录时
    this.setData({
      user: {
        photo: "http://m.qpic.cn/psc?/V125C4nA0idrYe/ruAMsa53pVQWN7FLK88i5h0uNd0H*bsq3.afgGbP062mtCBvJDWOSBthqODbjFhr011C.diIY9Z3i2T0eCHVlevniCUfB.KrWrB*7VCLmZk!/mnull&bo=yADIAAAAAAADByI!&rf=photolist&t=5",
        pwd: "",
        sex: "未知",
        uid: 0,
        uname: "请先登录",
        uno: ""
      }
    })
    //如果已登录

    if (wx.getStorageSync('user') != "") {
      this.setData({
        user:wx.getStorageSync('user')
      });
    }
  },
  onShow() {
    const userinfo = wx.getStorageSync("userinfo");
    const collect = wx.getStorageSync("collect") || [];

    this.setData({
      userinfo,
      collectNums: collect.length
    });
    this.showUserInfo();

  },
  toBaseInfo:function(){
    if(wx.getStorageSync('user')!=""){
      wx.navigateTo({
        url: '../userInfo/index',
      })
    }else{
      wx.navigateTo({
        url: '../demo/index',
      })
    }
  }

})